package edu.uj.petri.view;

import edu.uj.petri.commands.Memento;
import edu.uj.petri.commands.Restorable;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class Label extends DiagramElement {
    private String text;

    private Point2D position;
    
    public Label( Point2D position, String text ) {
        
        this.position = position;
        this.text = text;
    }
    
    public void setPosition( Point2D position )
    {
        this.position = position;
    }

    /**
     * get rectangle for text from Canvas
     */
    public boolean containsPoint(Point2D point) {        
        //return getElementRect().contains( point );
        return false;
    }

    /**
     * get rectangle for text from Canvas
     */
    public boolean crossesRectangle(Rectangle2D rect) {        
        //return getElementRect().intersects( rect );
        return false;
    }

    public void draw(Canvas canvas) {
        canvas.drawText(text, position); 
    }

    public void setSelected(boolean selected) {
        // olewam... a moĹĽe by tak wyjÄ…tek rzuciÄ‡?
    }

    /**
     * return containsPoint()
     */
    public boolean canBeMoved(Point2D startPoint) {
        //return containsPoint(startPoint);
        return false;
    }

    public void move(Point2D start, Point2D end) {
        
        Point2D difference = new Point2D.Double( start.getX() - end.getX(), start.getY() - end.getY());
        position.setLocation( position.getX() + difference.getX(), position.getY() + difference.getY());        
    }

    public void doubleClick( Point2D point ) {
    }

    /**
     * no entries
     */
    public ContextMenu getContextMenu() {
        return new ContextMenu(); // empty
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void removeFrom(View view) {
        
        removed = true;
    }

    public Memento getMemento() {
        LabelMemento retval = new LabelMemento();
        retval.position = (Point2D)this.position.clone();
        retval.text = this.text;
        return retval;
    }

    public void applyMemento(Memento memento) {
        LabelMemento myMemento = (LabelMemento)memento;
        this.position = (Point2D)myMemento.position.clone();
        this.text = myMemento.text;
    }
    
    static class LabelMemento extends Memento {
        private Point2D position;
        private String text;
    }

   // private Rectangle2D getElementRect() {
        
        //Dimension2D textSize = canvas.getTextSize( text );
        //return new Rectangle2D.Double( position.getX(), position.getY(), textSize.getWidth(), textSize.getHeight() );
   // }
    
    private static final long serialVersionUID = -782138887596604323L;
}
